﻿using A.M.ETO;
using L.M.System.Application.IServices;
using L.M.System.Application.Services;
using L.M.System.Domain.DTO;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using System.Security.Cryptography;

namespace L.M.System.Read.API.Controllers
{
    
    [Route("api/[controller]/[action]")]
    [ApiController]  
    public class Employee_role_tableReadController : ControllerBase  
    {
        private readonly IEmployee_role_tableServices employee_Role_TableServices;
        public Employee_role_tableReadController(IEmployee_role_tableServices employee_Role_TableServices)
        {
            this.employee_Role_TableServices = employee_Role_TableServices;
        }

        /// <summary>
        /// 清空用户的角色
        /// </summary>
        /// <param name="eId">用户编号</param>
        /// <returns>清空用户的角色</returns>
        [HttpDelete]
        public async Task<IActionResult> DelEmpInfor(string? eId)
        {
            return Ok(await employee_Role_TableServices.DelEmpInfor(eId));
        }

        /// <summary>
        /// 批量清空
        /// </summary>
        /// <param name="empinfor_RoleDTOs"></param>
        /// <returns>批量清空</returns>
        [HttpPost]
        public async Task<IActionResult> DelInforAll(List<Empinfor_roleDTO> empinfor_RoleDTOs)
        {
            return Ok(await employee_Role_TableServices.DelInforAll(empinfor_RoleDTOs));
        }


        /// <summary>
        /// 获取该角色下所有的用户编号
        /// </summary>
        /// <returns>获取该角色下所有的用户编号</returns>
        [HttpGet]
        public async Task<IActionResult> GetEnumInfor(string? rId)
        {
            return Ok(await employee_Role_TableServices.GetEnumInfor(rId));
        }

        /// <summary>
        /// 获取该角色下所有的用户名称
        /// </summary>
        /// <returns>获取该角色下所有的用户编号</returns>
        [HttpGet]
        public async Task<IActionResult> GetEnumInforName(string? rId)
        {
            return Ok(await employee_Role_TableServices.GetEnumInforName(rId));
        }

        /// <summary>
        /// 删除用户信息
        /// </summary>
        /// <param name="sId">编号</param>
        /// <returns>统一返回格式</returns>
        [HttpDelete]
        public async Task<IActionResult> StaffDelInfor(string? sId)
        {
            return Ok(await employee_Role_TableServices.StaffDelInfor(sId));
        }

        /// <summary>
        /// 获取用户的角色
        /// </summary>
        /// <param name="uId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetUserRole(string? uId)
        {
            var res = await employee_Role_TableServices.GetShowObjAsync(c => c.employee_number == uId);
            if (res != null)
            {
                return Ok(res.role_number);
            }
            else
            {
                return Ok("");
            }
        }
    }
}
